package com.security;

import com.utils.R;
import com.utils.RestResponse;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

/**
 * @author t-zhaoheng
 * @since 2022/3/28
 */
@Component
@Slf4j
public class MyAuthenticationFailureHandler extends
    JSONAuthentication implements AuthenticationFailureHandler {

  @Override
  public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
      AuthenticationException exception) throws IOException {
    this.writeJSON(response, R.error(exception.getMessage()));
  }
}
